<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="4" :sm="6">
          <a-form-item :label=" $t('light.gateWay') ">
            <a-select  v-model="queryParam.deviceId" :placeholder="$t('base.pleaseChoose')">
              <a-select-option v-for="item in gatewayList"  :value="item.gateWayCode">
                {{item.gatewayName}}
              </a-select-option>
            </a-select>
          </a-form-item>
          </a-col>

          <a-col :md="4" :sm="6">
            <a-form-item :label=" $t('light.lightCode') ">
              <j-input :placeholder="输入编号模糊查询" v-model="queryParam.ligCode"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="6">
            <a-form-item :label=" $t('faultAlerm.processingStatus') ">
              <j-dict-select-tag  v-model="queryParam.status" :placeholder="$t('base.pleaseChoose')" dictCode="glr_dispose_status"/>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="4">
            <a-form-item :label=" $t('base.createTime') ">
              <a-range-picker
                style="width: 210px"
                v-model="queryParam.faultDateRange"
                format="YYYY-MM-DD"
                ::placeholder="[ $t('base.startTime') , $t('base.endTime') ]"
                @change="onDateChange"
              />
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search"> {{$t('base.query')}} </a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px"> {{$t('base.reset')}} </a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="batchDel"  type="primary" icon="delete"> {{$t('base.del')}} </a-button>
      <a-button @click="processing"  type="primary" icon="delete"> {{$t('faultAlerm.dealWithFaults')}} </a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> {{$t('base.selected')}} <a style="font-weight: 600">{{ selectedRowKeys.length }}</a> {{$t('base.item')}}
        <a style="margin-left: 24px" @click="onClearSelected"> {{$t('base.clear')}} </a>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm :title="$t('base.confirmDelete')" @confirm="() => handleDelete(record.id)">
            <a> <a-icon type="delete" /> {{$t('base.del')}} </a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <glrFaultAlerm-modal ref="modalForm" @ok="modalFormOk"></glrFaultAlerm-modal>
  </a-card>
</template>
<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import GlrFaultAlermModal from './modules/GlrFaultAlermModal'
  import { httpAction } from '@/api/manage'
  import { filterObj } from '@/utils/util';
  import JInput from '@/components/jeecg/JInput'
  import JDate from '@/components/jeecg/JDate'
  export default {
    name: "GlrFaultAlermList",
    mixins:[JeecgListMixin],
    components: {
      GlrFaultAlermModal,
        JInput,
        JDate
    },
    data () {
      return {
        description: this.$t('faultAlerm.faultAlerm'),
        isorter:{column: 'faultDate', order: 'desc'},
          gatewayList:[],
          queryParam: {
              faultDateRange:[],
          },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:this.$t('light.equipmentName') ,
            align:"center",
            dataIndex: 'deviceName'
          },
          {
            title:this.$t('light.equipmentType') ,
            align:"center",
            dataIndex: 'deviceType_dictText'
          },
          {
            title:this.$t('faultAlerm.alarmLevel'),
            align:"center",
            dataIndex: 'alertLevel_dictText'
          },
          {
            title:this.$t('base.status'),
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:this.$t('faultAlerm.faultDate') ,
            align:"center",
            dataIndex: 'faultDate'
          },
          {
            title:this.$t('faultAlerm.faultCause') ,
            align:"center",
            dataIndex: 'contentMessage'
          },
          {
            title: this.$t('base.operation'),
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/glr/glrFaultAlerm/list",
          delete: "/glr/glrFaultAlerm/delete",
          deleteBatch: "/glr/glrFaultAlerm/deleteBatch",
          exportXlsUrl: "/glr/glrFaultAlerm/exportXls",
          importExcelUrl: "glr/glrFaultAlerm/importExcel",
          processing: "/glr/glrFaultAlerm/processing",
          getGateWay: "/glr/glrGateway/getGateWay",


        },
        dictOptions:{
        },
      }
    },
    created(){
        var that = this;
        httpAction(this.url.getGateWay,null,"post").then((res)=>{
            if(res.success){
                that.gatewayList=res.result;
            }else{
              //that.$message.warning(res.message);
              that.$message.warning(that.$t('base.operationFailed'));
            }
        }).finally(() => {
            that.confirmLoading = false;
        })
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      processing(){
          if (this.selectedRowKeys.length <= 0) {
            this.$message.warning(this.$t('base.pleaseSelectARecord'));
            return;
          } else {
            var ids = "";
            for (var a = 0; a < this.selectedRowKeys.length; a++) {
              ids += this.selectedRowKeys[a] + ",";
            }
            var that = this;
            this.$confirm({
              title: that.$t('base.confirm') ,
              content: that.$t('faultAlerm.confirmFaultResolved'),
              onOk: function () {
                that.loading = true;
                httpAction(that.url.processing, {ids: ids},"post").then((res) => {
                  if (res.success) {
                    //that.$message.success(res.message);
                    that.$message.success(that.$t('base.operationSuccessful'));
                    that.loadData();
                    that.onClearSelected();
                  } else {
                    //that.$message.warning(res.message);
                    that.$message.warning(that.$t('base.operationFailed'));
                  }
                }).finally(() => {
                  that.loading = false;
                });
              }
            });
          }
        },
        onDateChange: function (value, dateString) {
            this.queryParam.faultDate_begin=dateString[0];
            this.queryParam.faultDate_end=dateString[1];
        },

        getQueryParams(){
            var param = Object.assign({}, this.queryParam,this.isorter);
            param.field = this.getQueryField();
            param.pageNo = this.ipagination.current;
            param.pageSize = this.ipagination.pageSize;
            delete param.faultDateRange; // 时间参数不传递后台
            if (this.superQueryParams) {
                param['superQueryParams'] = encodeURI(this.superQueryParams)
                param['superQueryMatchType'] = this.superQueryMatchType
            }
            return filterObj(param);
        },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>